/**
 * 
 */
package com.google.code.onlineshopping4j.controller;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.code.onlineshopping4j.exception.OnlineShoppingException;
import com.google.code.onlineshopping4j.service.DashBoardService;

/**
 * @author TelmilaJ
 *
 */
@Controller
public class DashBoardController {
	

	public static final String DASHBOARD_REQUEST_MAPPING = "/dashboard";
	public static final String DASHBOARD_VIEW_NAME = "dashboard";
	
	private Logger logger = LoggerFactory.getLogger(DashBoardController.class);
	@Autowired
	private DashBoardService dashBoardService;
	
	@RequestMapping(value=DASHBOARD_REQUEST_MAPPING, method = RequestMethod.GET)
	public String showDashboard(ModelMap model, HttpServletRequest request, HttpSession session, Principal principal) {
		try {
			model.addAttribute("products", dashBoardService.getAllProduct());
		} catch (OnlineShoppingException exp) {
			logger.warn(exp.getMessage());
		} catch (Exception exp) {
			logger.warn(exp.getMessage());
		} 
		
		return DASHBOARD_VIEW_NAME;
 	}


}
